package com.simba.server.commands.impl.update;

import com.simba.common.command.ICommand;
import com.simba.common.database.DbOperator;

import java.util.List;

public class RenewSlotPackSyncCmd implements ICommand {
    public static final String NAME = "RenewSlotPackSyncCmd";
    private final List<Integer> idList;
    private String sql = "update tt_slot_pack_info set syncFlag=1 ";

    public RenewSlotPackSyncCmd(List<Integer> idList)
    {
        this.idList = idList;
    }
    @Override
    public String getName() {
        return RenewSlotPackSyncCmd.NAME;
    }

    @Override
    public Boolean run(Object params) {
        Boolean ret = false;

        if (!(params instanceof DbOperator))
        {
            return ret;
        }

        if (idList == null || idList.size() < 1)
        {
            return ret;
        }

        try
        {
            DbOperator dbOperator = (DbOperator) params;

            StringBuilder list = new StringBuilder();
            boolean isFirst = true;
            for (Integer id : idList)
            {
                if (isFirst)
                {
                    isFirst = false;
                }
                else
                {
                    list.append(",");
                }
                list.append(id);
            }
            sql += "where id in (" + list.toString() + ")";
            dbOperator.prepareStatement(this.sql);
            int rs = dbOperator.executeUpdate();

            if (rs > 0)
            {
                ret = true;
            }
        }
        catch (Exception ex)
        {
            ret = false;
        }

        return ret;
    }
}
